/**
 * Created by Administrator on 2016/6/30.
 */


//banner1滑动
$(function() {
    $(".flexslider").flexslider({
        slideshowSpeed: 4000, //展示时间间隔ms
        animationSpeed: 400, //滚动时间ms
        touch: true //是否支持触屏滑动
    });
});
//搜索栏滑动效果
$(function(){
    $(".mainPart").scroll(function(){
        if($(".mainPart").scrollTop()>433){
            $("header").fadeIn(600);
        }else{
            $("header").fadeOut(600);
        }
    }).trigger('scroll');
});
//首页的一些跳转链接
$(document).ready(function(){
    $("header img:first-child").unbind();
    $("#input").click(function(e){
        location.href = "searchDoctor.html";
        e.preventDefault();
    })
    $("#findMsg").click(function(){
        location.href = "searchDoctor.html";
    })
    $("#find").click(function(){
        location.href = "searchDoctor.html";
    })
    $("#inform").click(function(e){
        location.href = "inform.html";
        e.stopPropagation();
    })
    $("header").click(function(){
        location.href = "searchDoctor.html";
    })
    $("header section").click(function(e){
        location.href = "inform.html";
        e.stopPropagation();
    })
    $(".doctorRecommend button").click(function(){
        location.href = "doctorList.html";
    })
    $(".entrance section:nth-child(1)").click(function(){
        location.href = "doctorList.html";
    })
    $(".entrance section:nth-child(2)").click(function(){
        location.href = " diaryBook.html";
    })
    $(".entrance section:nth-child(3)").click(function(){
        if(u_id){
            location.href = "doctorJoin.html";
        }else{
            location.href = "register.html?jump=4";
        }
    })
    $(".mainPart button").click(function(){
        location.href = "doctorList.html";
    })


});


//调用名医推荐接口
$(document).ready(function(){
    $.ajaxSettings.async=false;
    $.post(commonval+"/index_data",{
        device:"wap"
    },function(data){
        if(data.status == 1){
            var consultList = new Vue({
                el: '#doctorRecommend',
                data: {
                    items: data.data.doctor_recommend
                }
            });
            $("#doctorRecommendALL").css("display","inherit");
            $(".entrance").css("display","inherit");
            var consultList = new Vue({
                el: '#mediumBanner',
                data: {
                    items: data.data.banner_middle
                }
            });
            var consultList = new Vue({
                el: '#slides',
                data: {
                    items: data.data.banner
                }
            });
        }
        $("#slides li").click(function(){
            var url = $(this).children("a").attr("value");
            location.href=url;
        })
        $("#mediumBanner section img").click(function(){
            var url = $(this).attr("value");
            location.href=url;
        })
        $("section.docListMember").click(function(){
            var url ="doctorInfo.html";
            var id = $(this).children(".rightPart").children("p.id").text();
            location.href = url+"?id="+id;
            sessionStorage.d_id = id;
        });
        $("#doctorRecommend").css("display","block");
    })
});
//banner2 滑动效果
$(function(){
    var $pad= $(".mediumBanner");
    var padWid=$pad.width();
    var width=padWid*0.46;
    var secWid=$(".mediumBanner section").width();
    $(".mediumBanner section").each(function(index){
        $(this).css('left',index*width);
    });
    $pad.on("swipeleft",function(){
        var $last=$(".mediumBanner section:last-child");
        var left=parseInt($last.css('left'));
        if (left > (2*width-30)){
            if (left < padWid) {
                $(".mediumBanner section").each(function(index){
                    var distance=parseInt($(this).css('left'))-left+padWid*0.62;
                    $(this).animate({left: distance+'px'},'slow');
                });
            }
            else {
                $(".mediumBanner section").each(function(index){
                    var distance=parseInt($(this).css('left'))-width;
                    $(this).animate({left: distance+'px'},'slow');
                });
            }
        }
    });
    $pad.on("swiperight",function(){
        var $first=$(".mediumBanner section:first-child");
        var left2=parseInt($first.css('left'));
        if (parseInt($first.css('left'))<0){
            if ( left2 > -secWid ){
                $(".mediumBanner section").each(function(index){
                    var distance=parseInt($(this).css('left'))-left2;
                    $(this).animate({left: distance+'px'},'slow');
                });
            }
            else {
                $(".mediumBanner section").each(function(index){
                    var distance=parseInt($(this).css('left'))+width;
                    $(this).animate({left: distance+'px'},'slow');
                });
            }
        }
    });
});


//获取未读通知数量
$(document).ready(function(){
    $.ajaxSettings.async=false;
    postArray.u_id = u_id;
    $.post(commonval+"/getNoticeNum",postArray,function(data){
        if(data.status == 1){
            if(data.data != 0){
                $("#num").text(data.data);
                $("#num").css("display","inline")
                $("header section span").text(data.data);
                $("header section span").css("display","inline")
            }
        }
    })
});
//待处理逻辑
$(document).ready(function(){
    if(u_id){
        postArray.u_id = u_id;
        $.post(commonval+"/PendingOrder",postArray,function(data){
            if(data.status == 1){
                if(data.data.is_received == 1 ||data.data.is_initiate == 1){
                    $("footer section:nth-child(2) img:nth-child(2)").css("display","inherit");
                    $("footer section:nth-child(2) p").css("margin-top","-43px");
                }
            }
        })
    }
});

//获取用户信息
if(u_id!==undefined){
    postArray.u_id = u_id;
    $.post(commonval+"/user_info",postArray,function(data){
        var sh_status = data.data.sh_status;
        var img = $(".entrance>img");
        if(sh_status == 3){
            img.css("display","none");
        }else if(sh_status == 0){
            img.css("display","inherit");
            img.attr("src","../images/beingAudit.png");
        }else if(sh_status == 1){
            img.css("display","inherit");
            img.attr("src","../images/conpleteAudit.png");
        }else if(sh_status == 2){
            img.css("display","inherit");
            img.attr("src","../images/failAudit.png");
        }
    });
}

